function filterJS(html, srcId = '-src') {
    const obj = document.createElement('div');
    obj.innerHTML = html;
    const _parseScripts = function () {
        const s = obj.getElementsByTagName('script');
        // For browsers which discard scripts when inserting innerHTML, extract the scripts using a RegExp
        if (s.length == 0) {
            // 有的时候在html中的script识别不出来，需用正则表达式解析，如: BasicTreeSelectCtl在convertToHTMLCtlForQuery生成查询字符串时就识别不出来
            const re =
                /(?:<script.*(?:src=[\"\'](.*)[\"\']).*>.*<\/script>)|(?:<script.*>([\S\s]*?)<\/script>)/gi; // assumes HTML well formed and then loop through it.
            let match;
            while ((match = re.exec(html))) {
                const s0 = document.createElement('script');
                console.log('s001', s0);
                if (match[1]) {
                    s0.src = match[1];
                    s0.id = `${300}${srcId}`;
                } else if (match[2]) {
                    s0.text = match[2];
                    s0.id = `${300}${srcId}`;
                }
                document.body.appendChild(s0);
            }
        } else {
            for (let i = 0; i < s.length; i++) {
                const s0 = document.createElement('script');
                if (s[i].text) {
                    s0.text = s[i].text;
                    s0.id = `${600}${srcId}`;
                } else {
                    s0.src = s[i].src;
                    s0.id = `${600}${srcId}`;
                }
                // console.log('s0', s0);
                document.body.appendChild(s0);
            }
        }
    };
    _parseScripts();
}

function getFormJs(formCode, skey) {
    try {
        $.ajax({
            type: "GET",
            url: '../flow/getFormJs',
            data: {
                formCode: formCode,
                skey: skey
            },
            contentType: "application/x-www-form-urlencoded; charset=iso8859-1",
            dataType: "html",
            success: function (data, status) {
                // console.log('getFormJs data', data);
                filterJS(data, '-src');
            },
            error: function (XMLHttpRequest, textStatus) {
                // 请求出错处理
                console.log(XMLHttpRequest.responseText);
            }
        });
    } catch (e) {
        console.error('myUrl', myUrl);
        console.error(e);
    }
}

function getMacroJs(macroCode, skey, flowId, fieldName, formCode, editable, pageType) {
    try {
        $.ajax({
            type: "GET",
            url: '../flow/getMacroJs',
            async: false,
            data: {
                macroCode: macroCode,
                skey: skey,
                flowId: flowId,
                fieldName: fieldName,
                formCode: formCode,
                editable: editable,
                pageType: pageType
            },
            contentType: "application/x-www-form-urlencoded; charset=iso8859-1",
            dataType: "html",
            success: function (data, status) {
                // console.log('getMacroJs data', data);
                filterJS(data, '-src');
            },
            error: function (XMLHttpRequest, textStatus) {
                // 请求出错处理
                console.log(XMLHttpRequest.responseText);
            }
        });
    } catch (e) {
        console.error('myUrl', myUrl);
        console.error(e);
    }
}